package link.jfire.socket.socketclient.filter;

import link.jfire.baseutil.collection.ByteCache;
import link.jfire.baseutil.encrypt.AesUtil;

public class AesFilter implements DataFilter
{
    private AesUtil aesUtil;
    
    @Override
    public void outFilter(ByteCache cache)
    {
        byte[] result = aesUtil.encrypt(cache.toArray());
        cache.clear().putArray(result);
    }
    
    @Override
    public void inFilter(ByteCache cache)
    {
        byte[] result = aesUtil.decrypt(cache.toArray());
        cache.clear().putArray(result);
    }
    
    public void setKey(byte[] key)
    {
        aesUtil = new AesUtil(key);
    }
    
}
